Sunmi Scan Code Driver


Why do you want to use our scanner driver


Sunmi have privide scanner driver ,  Compared with the currently used plan ,below are five advantages :


1.A higher recognition rate,we have tested for a long time ,Sunmi scanner driver's recognition rate has improved by 64% than ZXing.


2.It is 100% faster than ZXing while scanning bar code .


3.It's easier to use, you just want add a few lines of code into your app to getting the results.


4.Supports up to 15 codes.


5. Perfect fit with our deveice,hardware and software combination ensures the efficient and stable.


How to use Sunmi scanner driver


Developer have two ways to use Sunmi scanner driver


1.Developer's app calling the SUNMIUI built-in scanner ,getting results, it's very simple.


2.Writing a custom camera yourself,calling Sunmi basic scanner driver, it's more complex than first way, but more freedom to use.


First way:

In order  to reduce the  difficulty of developer  using it ,Sunmi has build-in a scanner module in the latest SUNMIUI(V1 firmware version 187,M1 firmware version 37). You can call startActivityForResult()

 method to start the scanner module where you app should do something scanning, and getting the results in onActivityResult() method.


Starting the scanner module as following code,


    /**

    * 

    *Creating a Intent at where you want start scanner, calling the scanner by startActiityForResult();

    */

    Intent intent = new Intent("com.summi.scan");

    intent.setPackage("com.sunmi.sunmiqrcodescanner");

            

    /**

    * The method is the same function as above 

    *Intent intent = new Intent("com.summi.scan");

    *intent.setClassName("com.sunmi.sunmiqrcodescanner", "com.sunmi.sunmiqrcodescanner.activity.ScanActivity");

    */


    /**


    //there is also some options item about the scanner module, you can transfer parameters to control some settings, each item has a defaut status,transform parameter is not necessary,

    intent.putExtra("CURRENT_PPI", 0X0003);//The current preview resolution ,PPI_1920_1080 = 0X0001;PPI_1280_720 = 0X0002;PPI_BEST = 0X0003;

    intent.putExtra("PLAY_SOUND", true);// Prompt tone after scanning  ,default true

    intent.putExtra("PLAY_VIBRATE", false);//vibrate after scanning,default false,only support M1 right now.

    intent.putExtra("IDENTIFY_INVERSE_QR_CODE", true);//Whether to identify inverse code

    intent.putExtra("IDENTIFY_MORE_CODE", false);// Whether to identify several code,default false        

    intent.putExtra("IS_SHOW_SETTING", true);// Wether display set up button  at the top-right corner,default true

    intent.putExtra("IS_SHOW_ALBUM", true);// Wether display album,default true

    */

    startActivityForResult(intent, START_SCAN);



getting the results in onActivityResult method . Refer to the following code


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                if (requestCode == 1 && data != null) {
                        Bundle bundle = data.getExtras();
                        ArrayList<HashMap<String, String>> result = (ArrayList<HashMap<String, String>>) bundle
                                        .getSerializable("data");
                        
                        Iterator<HashMap<String, String>> it = result.iterator();

                        while (it.hasNext()) {
                                HashMap<String, String> hashMap = it.next();
                                
                                Log.i("sunmi", hashMap.get("TYPE"));//this is the type of the code 
                                Log.i("sunmi", hashMap.get("VALUE"));//this is the result of the code 
                                
                        }

                }
                super.onActivityResult(requestCode, resultCode, data);
        }


The second way:


In principle ,before you use Sunmi scanner driver, you should know some basic knowledge about android custom camera, if you are a rookie,

you can download this resources file and refer to the SunmiScnnerDemo code comments,below is an example based on SunmiScanDemo 

showing you the basic use of Sunmi scanner driver, this is a project base on eclipse.


1.Adding four resource package libiconv.so,libscaninit.so,libsunmiscan.so,sunmiscan.jar into libs as following hierarchy.


project



2.Import head file and decoding library,please refer to the Demo.


import com.sunmi.scan.Config;
import com.sunmi.scan.Image; 
import com.sunmi.scan.ImageScanner; 
import com.sunmi.scan.Symbol;
import com.sunmi.scan.SymbolSet; 


3.Initialization and configuration.

private ImageScanner scanner;// declare the scanner
scanner = new ImageScanner();// create a scanner
scanner.setConfig(0, Config.X_DENSITY, 2);// the interval time of line
scanner.setConfig(0, Config.Y_DENSITY, 2);//the interval time of raw
scanner.setConfig(0, Config.ENABLE_MULTILESYMS, 0);
//turn on the multiple parse in one picture, 0 means one , 1 means multiple
scanner.setConfig(0, Config.ENABLE_INVERSE, 0);// turn on the reserve color ?

4.Incoming image data and decoding, you can write following code in PreviewCallback.onPreviewFrame(byte[] data, Camera camera) method;



    /**

    creating image,width is the preview image's width and  height is the preview image's height,generally speaking,high generally speaking also means clearer image,but slower decoding speed.cause the decoding arithmetic need the the original data and the default format of the preview image is YCbCr_420_SP,you must transform the fromat, parameter "Y800" is the format of image what you want transform.

    */

    Image source = new Image(width, height, "Y800");


    /**

    *Set the scan area

    */

    Rect cropRect = finder_view.getScanImageRect(size.height, size.width);//finder_view is the custom widget of the demo

    source.setCrop(cropRect.top,cropRect.left,cropRect.height(),cropRect.width());


    /*filling the data, this is the source data of camera*/

    source.setData(data); 


    /*decoding ,return value 0 means failure,>0 means successful*/

    int result = scanner.scanImage(source); 



    Rect cropRect = finder_view.getScanImageRect(size.height, size.width);

    source.setCrop(cropRect.top,cropRect.left,cropRect.height(),cropRect.width());


    /*filling the data,this is the source data of camera*/

    source.setData(data); 


    /*decode,returned value 0 means failure,>0 means success*/

    int result = scanner.scanImage(source); 

5.Getting the code type and data result.



    if (result != 0) {

             

        SymbolSet syms = scanner.getResults();

            for (Symbol sym : syms) {   

              Log.i("sunmi", "type:"+sym.getSymbolName());//code type,such as “EAN-8”

              Log.i("sunmi","result:"+sym.getResult())//getting the result

                

              }


    }


More tips 

Following is thoese codes what we support right now:
One dimensional code:EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code39, Code93, Code128, ISBN10, ISBN13, DataBar, DataBar  Expanded, Interleaved 2 of 5


Two-dimensional code: QR Code , PDF417